package com.bweab.dao.impl.en;

import com.bweab.dao.api.En.DepositTbDaoEnInterface;
import com.bweab.dao.base.BaseDao;
import com.bweab.pojo.en.DepositTbPageEn;

import java.util.List;

/**
 * 充值页面操作的实现
 */
public class DepositTbDaoEnInterfaceImpl extends BaseDao<DepositTbPageEn> implements DepositTbDaoEnInterface {
    /**
     * @param depositId 充值记录id
     * @param page      当前页面
     * @param pageSize  页面大小
     * @return 返回depositTbEnPage
     */
    @Override
    public List<DepositTbPageEn> queryDepositInfoByDepositId(int depositId, int page, int pageSize) {
        //start
        int start;
        //准备sql
        String sql="select\n" +
                "    (select count(*) from deposit_tb  where deposit_id=?) totalCount,\n" +
                "    dst.deposit_id  depositId,\n" +
                "    dst.user_id userId,\n" +
                "    dst.dormitory_id dormitoryId,\n" +
                "    dst.deposit_monkey depositMonkey,\n" +
                "    dst.deposit_time depositTime\n" +
                "from deposit_tb dst\n" +
                "where deposit_id=?\n"+
                "limit ?,?"
                ;
        //对页面进行判断
        if(page==0){
            start=0;
        }else {
            start=(page-1)*pageSize;
        }

        List<DepositTbPageEn> depositTbPageEns = queryList(sql, DepositTbPageEn.class, depositId,depositId, start, pageSize);
        return depositTbPageEns;
    }

    /**
     *
     * @param dormitoryId 宿舍id
     * @param page          当前页面
     * @param pageSize      页面大小
     * @return 返回结果是一个集合
     */
    @Override
    public List<DepositTbPageEn> queryDepositInfoByDormitoryId(int dormitoryId, int page, int pageSize) {

        //准备sql语句
        String sql= "select\n" +
                "    (select count(*) from deposit_tb  where dormitory_id=?) totalCount,\n" +
                "    dst.deposit_id  depositId,\n" +
                "    dst.user_id userId,\n" +
                "    dst.dormitory_id dormitoryId,\n" +
                "    dst.deposit_monkey depositMonkey,\n" +
                "    dst.deposit_time depositTime\n" +
                "from deposit_tb dst\n" +
                "where dormitory_id=?\n"+
                "limit ?,?"
                ;
        int start;
        //对页面进行处理
        if(page==1){
            start=0;
        }else{
            start= (page-1) * pageSize;
        }

        List<DepositTbPageEn> depositTbPageEns = queryList(sql, DepositTbPageEn.class,dormitoryId,dormitoryId,start,pageSize);
        System.out.println("数据库dao层");
        System.out.println(depositTbPageEns);
        return depositTbPageEns;
    }

    /**
     *
     * @param userId  用户id
     * @param page      当前页数
     * @param pageSize  页面的大小
     * @return 返回结果是一个depositEn的集合
     */
    @Override
    public List<DepositTbPageEn> queryDepositInfoByUserId(int userId, int page, int pageSize) {

        //准备sql语句
        String sql= "select\n" +
                "    (select count(*) from deposit_tb  where user_id=?) totalCount,\n" +
                "    dst.deposit_id  depositId,\n" +
                "    dst.user_id userId,\n" +
                "    dst.dormitory_id dormitoryId,\n" +
                "    dst.deposit_monkey depositMonkey,\n" +
                "    dst.deposit_time depositTime\n" +
                "from deposit_tb dst\n" +
                "where user_id=?\n"+
                "limit ?,?"
                ;
        int start;
        //对页面进行处理
        if(page==1){
            start=0;
        }else{
            start= (page-1) * pageSize;
        }

        List<DepositTbPageEn> depositTbPageEns = queryList(sql, DepositTbPageEn.class,userId,userId,start,pageSize);
        System.out.println("数据库dao层");
        System.out.println(depositTbPageEns);
        return depositTbPageEns;

    }
}
